<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Mint;
use App\Models\Nft;
use App\Models\User;
use App\Services\DogecoinService;
use Carbon\Carbon;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('Dashboard')
            ->description('数据统计...')
            ->body(function (Row $row) {
                $row->column(4, function (Column $column) {
                    $column->row(Card::make('DOGE转账地址', 'D8KhP2328hZ1dSo6zBnksGy7EFwLFuTnCF'));
                });
                $row->column(4, function (Column $column) {
                    $service  = new DogecoinService();
                    try {
                        $r = $service->walletInfo();
                        $balance = $r['balance'].'/'.$r['unconfirmed_balance'];
                    }catch (\Exception $e) {
                        $balance = '获取失败';
                    }
                    $column->row(Card::make('DOGE转账地址余额：可用/未确认', $balance));
                });
                $row->column(3, function (Column $column) {
                    $count = User::count();
                    $column->row(Card::make('总用户数量', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = Nft::count();
                    $column->row(Card::make('总NFT数量', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = Mint::sum('amount');
                    $column->row(Card::make('总出矿数量', $count));
                });
            });
    }
}
